package com.haoshuang.zhouzhoubang.ui.page.order.scan.writeoffresult

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ActivityWriteOffResultBinding
import com.haoshuang.zhouzhoubang.ui.page.main.MainActivity
import com.haoshuang.zhouzhoubang.ui.page.order.scan.ScanActivity
import com.haoshuang.zhouzhoubang.ui.page.order.scan.ScanViewModel
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.clickWithTrigger

/**
 * 核销
 */
class WriteOffResultActivity : BaseVMActivity<ScanViewModel, ActivityWriteOffResultBinding>() {


    var isSuccess = false
    var msg = ""

    companion object {

        fun launch(
            context: Context,isSuccess:Boolean,msg:String
        ) {
            context.startPage<WriteOffResultActivity>("isSuccess" to isSuccess,"msg" to msg)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        binding.titleBar.title = "核销订单"
        binding.titleBar.leftImageView().click { finish() }

        isSuccess = intent.getBooleanExtra("isSuccess",false)
        msg = intent.getStringExtra("msg")?:""

        if (isSuccess){
            binding?.ivResult?.setImageResource(R.mipmap.icon_hxcg)
            binding?.tvBack?.text = "查看核销订单"
            binding?.tvBack?.clickWithTrigger {
                val intent = Intent(this@WriteOffResultActivity, MainActivity::class.java)
                intent.putExtra("index", "3-0")   //跳转到主页-订单-已完成
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
                this@WriteOffResultActivity.startActivity(intent)
            }
        }else{
            binding?.ivResult?.setImageResource(R.mipmap.icon_hxsb)
            binding?.tvBack?.text = "返回"
            binding?.tvBack?.clickWithTrigger {
                finish()
            }
        }
        binding?.tvResult?.text = msg



        binding?.tvJixuhexiao?.clickWithTrigger {
            ScanActivity.launch(this@WriteOffResultActivity)
        }
    }

    override fun initData() {

    }
}